package gew.sql;

import gew.utils.SqlUtils;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Scanner;

public abstract class SqlTemplates {
    public final static String LOG_HEADER = SqlTemplates.class.getResource("log_header.sql").getPath();
    public final static String LOG_COOKIE = SqlTemplates.class.getResource("log_cookie.sql").getPath();
    public final static String LOG_REQUEST = SqlTemplates.class.getResource("log_request.sql").getPath();
    public final static String HIER_PARTNER_URL_COLLAPSE = SqlTemplates.class.getResource("hier_partner_url_collapse.sql").getPath();
    public final static String DIMENSION_TRADE_FLOW = SqlTemplates.class.getResource("dimension_trade_flow.sql").getPath();
    public final static String DIMENSION_PERIOD = SqlTemplates.class.getResource("dimension_period.sql").getPath();
    public final static String DIMENSION_INDICATOR = SqlTemplates.class.getResource("dimension_indicator.sql").getPath();
    public final static String DIMENSION_COUNTRY = SqlTemplates.class.getResource("dimension_country.sql").getPath();
    public final static String DIMENSION_COMMODITY_GROUP_TYPE = SqlTemplates.class.getResource("dimension_commodity_group_type.sql").getPath();
    public final static String DIMENSION_COMMODITY = SqlTemplates.class.getResource("dimension_commodity.sql").getPath();
    public final static String DIMENSION_SECTION = SqlTemplates.class.getResource("dimension_section.sql").getPath();
    public final static String TABLE_COLUMN_VALUE = SqlTemplates.class.getResource("table_column_value.sql").getPath();
    public final static String TABLE_COLUMN = SqlTemplates.class.getResource("table_column.sql").getPath();
    public final static String TABLE_DIMENSION_CONDITION_NO_PARENTS = SqlTemplates.class.getResource("table_dimension_condition_no_parents.sql").getPath();
    public final static String TABLE_DIMENSION = SqlTemplates.class.getResource("table_dimension.sql").getPath();
    public final static String FILTER_WORDS_COMMODITY = SqlTemplates.class.getResource("filter_words_commodity.sql").getPath();
    public final static String FILTER_WORDS_PERIOD = SqlTemplates.class.getResource("filter_words_period.sql").getPath();
    public final static String FILTER_WORDS_COUNTRY = SqlTemplates.class.getResource("filter_words_country.sql").getPath();
    public final static String FILTER_WORDS_INDICATOR = SqlTemplates.class.getResource("filter_words_indicator.sql").getPath();
    public final static String TREE_SEARCH_IDS = SqlTemplates.class.getResource("tree_search_ids.sql").getPath();
    public final static String TREE_SEARCH_COMMODITY = SqlTemplates.class.getResource("tree_search_commodity.sql").getPath();
    public final static String TREE_SEARCH = SqlTemplates.class.getResource("tree_search.sql").getPath();
    public final static String TREE_INIT = SqlTemplates.class.getResource("tree_init.sql").getPath();
    public final static String TREE_CHILDREN = SqlTemplates.class.getResource("tree_children.sql").getPath();
    public final static String TRADE_LOAD_PREPARATION = SqlTemplates.class.getResource("trade_load_preparation.sql").getPath();
    public final static String TRADE_LOAD_EXECUTION = SqlTemplates.class.getResource("trade_load_execution.sql").getPath();
    public final static String TRADE_LOAD_INP_TRADE_DATA_ID_SELECT_DELETE_STMTS = SqlTemplates.class.getResource("trade_load_inp_trade_data_id_select_delete_stmts.sql").getPath();
    public final static String TRADE_LOAD_INP_TRADE_DATA_ID_SELECT_PARTITIONS = SqlTemplates.class.getResource("trade_load_inp_trade_data_id_select_partitions.sql").getPath();
    public final static String TRADE_LOAD_CLS_LOAD_REQUEST_UPDATE_COUNT = SqlTemplates.class.getResource("trade_load_cls_load_request_upd_count.sql").getPath();
    public final static String TRADE_LOAD_CLS_LOAD_REQUEST_UPDATE_TO_READY = SqlTemplates.class.getResource("trade_load_cls_load_request_upd_to_ready.sql").getPath();
    public final static String TRADE_LOAD_CLS_LOAD_REQUEST_UPDATE_TO_FAILED = SqlTemplates.class.getResource("trade_load_cls_load_request_upd_to_failed.sql").getPath();
    public final static String TRADE_LOAD_CLS_LOAD_REQUEST_UPDATE_TO_EXECUTED = SqlTemplates.class.getResource("trade_load_cls_load_request_upd_to_executed.sql").getPath();
    public final static String TRADE_LOAD_CLS_LOAD_REQUEST_UPDATE_TO_EXECUTION = SqlTemplates.class.getResource("trade_load_cls_load_request_upd_to_execution.sql").getPath();
    public final static String TRADE_LOAD_CLS_LOAD_REQUEST_NEXT = SqlTemplates.class.getResource("trade_load_cls_load_request_next.sql").getPath();
    public final static String TRADE_LOAD_CLS_LOAD_REQUEST_INSERT = SqlTemplates.class.getResource("trade_load_cls_load_request_insert.sql").getPath();
    public final static String TABLE_INDICATORS_VALUE_FORMAT = SqlTemplates.class.getResource("table_indicators_value_format.sql").getPath();
    public final static String TABLE_INDICATORS_YEARS = SqlTemplates.class.getResource("table_indicators_years.sql").getPath();
    public final static String TABLE_INDICATORS_ORDER_BY = SqlTemplates.class.getResource("table_indicators_order_by.sql").getPath();
    public final static String TABLE_INDICATORS = SqlTemplates.class.getResource("table_indicators.sql").getPath();
    public final static String GRAPH_INDICATORS_VALUE = SqlTemplates.class.getResource("graph_indicators_value.sql").getPath();
    public final static String GRAPH_INDICATORS = SqlTemplates.class.getResource("graph_indicators.sql").getPath();
    public final static String GRAPH_TRADE_TOPN_PARTNERS = SqlTemplates.class.getResource("graph_trade_topn_partners.sql").getPath();
    public final static String GRAPH_TRADE_TOPN_PARTNERS2 = SqlTemplates.class.getResource("graph_trade_topn_partners2.sql").getPath();
    public final static String MENU_INDICATORS = SqlTemplates.class.getResource("menu_indicators.sql").getPath();
    public final static String MENU_INDUSTRIES = SqlTemplates.class.getResource("menu_industries.sql").getPath();
    public final static String MENU_TRADE = SqlTemplates.class.getResource("menu_trade.sql").getPath();
    public final static String INDICATOR_SUMMARY = SqlTemplates.class.getResource("indicator_summary.sql").getPath();
    public final static String INDICATOR_SUMMARY_INDICATORS = SqlTemplates.class.getResource("indicator_summary_indicators.sql").getPath();
    public final static String TRADE_SUMMARY = SqlTemplates.class.getResource("trade_summary.sql").getPath();
    public final static String TRADE_SUMMARY_DEFAULT_COMMODITY = SqlTemplates.class.getResource("trade_summary_default_commodity.sql").getPath();
    public final static String TRADE_SUMMARY_DEFAULT_COMMODITY_CLASSIFICATION = SqlTemplates.class.getResource("trade_summary_default_commodity_classification.sql").getPath();
    public final static String TRADE_SUMMARY_DEFAULT_PARTNER = SqlTemplates.class.getResource("trade_summary_default_partner.sql").getPath();
    public final static String TRADE_SUNBURST_GRAPH = SqlTemplates.class.getResource("trade_sunburst_graph.sql").getPath();
    private final static HashMap<String, String> sqlTemplates = new HashMap<>();

    public static String getSql(String key) {
        if (!sqlTemplates.containsKey(key)) {
            initTemplate(key);
        }
        return sqlTemplates.get(key);
    }

    private static void initTemplate(String key) {
        String t = "";
        try (Scanner in = new Scanner(new FileReader(key))) {
            while (in.hasNext()) {
                t = t.concat(SqlUtils.SPACE).concat(in.next());
            }
        } catch (Exception e) {
            t = "";
        }
        sqlTemplates.put(key, t);
    }
}
